package com.chat.service;

import com.chat.common.EmailMessage;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.common.User;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
/*
   用于邮件发送服务
 */
public class EmailService {
    private static final User user=new User();
    private static final Message msg=new Message();
    private static Socket socket;
   public  static boolean emailservice(String content,String address){
                 boolean b=true;
                 msg.setMesType(MessageType.MESSAGE_EMAIL);
                 EmailMessage em=new EmailMessage();
                 long t=System.currentTimeMillis();
                 em.setTime(t);
                 em.setContent(content);
                 em.setAddress(address);
                 msg.setData(em);
       try {
           socket=new Socket(InetAddress.getByName("127.0.0.1"),9999);
           ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
           msg.setMesType(MessageType.MESSAGE_EMAIL);
           oos.writeObject(msg);

       } catch (IOException e) {
           e.printStackTrace();
       }finally {
           try {
               socket.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       return b;
   }
}
